package red.book._1._1;

public class Queue<T> {
    private Node<T> first;
    private Node<T> last;
    private int N;

    private class Node<T>{
        Node<T> next;
        T t;
    }

    public boolean isEmpty(){
        return first == null;
    }

    public void enqueue(T t){
        Node<T> oldLast = last;
        last = new Node<T>();
        last.t = t;
        if(isEmpty())
            first = last;
        else
            oldLast.next = last;
        N++;
    }

    public T dequeue(){
        T t = first.t;
        first = first.next;
        if (isEmpty())
            last = first;
        N--;
        return t;
    }
}
